package com.DAO.Impl;

import com.DAO.MenuDAO;
import com.DBUtil.DBUtil;
import com.entity.Menu;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

/**
 * @author 20x
 * @date 2024 - 12 -12
 **/
public class MenuDAOImpl implements MenuDAO {
    @Override
    public Menu getMenuById(String MenuId) {
        //根据id查询套餐
        Menu menu = null;
        String sql = "select * from menu where menuId = ?";
        ResultSet rs = null;
        PreparedStatement pst = null;
        Connection conn = DBUtil.getConnection();
        try {
            pst = conn.prepareStatement(sql);
            pst.setString(1, MenuId);
            rs = pst.executeQuery();
            if (rs.next()) {
                menu = new Menu(rs.getString(1), rs.getString(2), rs.getString(3), rs.getString(4), rs.getString(5), rs.getString(6), rs.getString(7), rs.getString(8), rs.getString(9), rs.getString(10), rs.getString(11));
            }
            DBUtil.close(rs,pst,conn);
        }
        catch (Exception e) {
            e.printStackTrace();
        }
        return menu;
    }

    public static void main(String[] args) {
    MenuDAOImpl menuDAO = new MenuDAOImpl();
    Menu menu = menuDAO.getMenuById("20");
    System.out.println(menu);
    }
}
